import Vue from 'vue'
import App from './App'
import { Toast } from 'mint-ui'
// 路由
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// 路由信息
import routes from './routerMap.js'

// 请求
import axios from 'axios'
import qs from 'qs'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
axios.defaults.withcredentials = true
    /** 统一设置后台请求地址 */
axios.defaults.baseURL = 'http://47.106.98.87:8083/ldy/'
Vue.prototype.$axios = axios

//POST传参序列化(添加请求拦截器)
axios.interceptors.request.use((config) => {
    //在发送请求之前如果为post序列化请求参数
    if (config.method === 'post') {
        config.data = qs.stringify(config.data);
    }
    return config;
}, (error) => {
    Toast({
        message: '传参错误，请检查！',
        duration: 1000
    });
    return Promise.reject(error);
});

//返回状态判断(添加响应拦截器)
axios.interceptors.response.use((res) => {
    //对响应数据做判断，与后台协议统一接口返回格式
//  if (res.data.succ !== 'ok') { //这个判断可根据实际情况修改
//      Toast({
//          message: res.data.msg ? res.data.msg : '服务器请求失败，请重试！',
//          duration: 1500
//      });
//      return Promise.reject(res);
//  }
//  return res;
	return res
}, (error) => {
    Toast({
        message: '网络异常，请稍后再试！',
        duration: 1500
    });
    return Promise.reject(error);
});


// mint-ui组件 按需引入，不需要就删除
/*-------- 这部分组件按需引入  开始--------*/
import {
    Header,
    Button,
    Cell,
    Actionsheet,
    Popup,
    TabContainer,
    TabContainerItem,
    Navbar,
    TabItem,
    Search,
    Badge,
    DatetimePicker,
    Switch,
    Range,
    Picker,
    InfiniteScroll,
    Field,
    Loadmore,
    CellSwipe,
    Lazyload,
    IndexList,
    IndexSection
} from 'mint-ui';

Vue.use(InfiniteScroll);
Vue.use(Lazyload);
Vue.component(CellSwipe.name, CellSwipe);
Vue.component(Header.name, Header);
Vue.component(Button.name, Button);
Vue.component(Cell.name, Cell);
Vue.component(Actionsheet.name, Actionsheet);
Vue.component(Popup.name, Popup);
Vue.component(TabContainer.name, TabContainer);
Vue.component(TabContainerItem.name, TabContainerItem);
Vue.component(Navbar.name, Navbar);
Vue.component(TabItem.name, TabItem);
Vue.component(Search.name, Search);
Vue.component(Badge.name, Badge);
Vue.component(DatetimePicker.name, DatetimePicker);
Vue.component(Switch.name, Switch);
Vue.component(Range.name, Range);
Vue.component(Picker.name, Picker);
Vue.component(Field.name, Field);
Vue.component(Loadmore.name, Loadmore);
Vue.component(IndexList.name, IndexList);
Vue.component(IndexSection.name, IndexSection);
/*-------- 这部分组件按需引入  结束--------*/

import FastClick from 'fastclick'
if ('addEventListener' in document) {
    document.addEventListener('DOMContentLoaded', function() {
        FastClick.attach(document.body);
    }, false);
}

import './js/flexible.js'
import VueGlobal from './js/global.js'
Vue.use(VueGlobal)

/*引入全局变量模块*/
import Global from './components/global'
Vue.prototype.GLOBAL = Global;
// 测试需要调试时开启
import './js/vconsole.min.js';


// LESS,CSS样式
import './css/common.less'
/* eslint-disable no-new */
const router = new VueRouter({
    //mode: 'history',
    base: __dirname,
    routes
})

new Vue({
        router,
        el: '#app',
        render: h => h(App)
  })



